package com.seven.springboot.enums;

import java.util.Map;

/**
 * 返回状态码
 * 
 * @author yinbenyang
 * @date 2018年7月3日下午12:02:12
 */
public enum StatusCode implements IndexedEnum {
	
	/**
	 * 1-10
	 */
	SUCCESS(ValidStatus.VALID.getIndex(), "成功"),
	FAILED(ValidStatus.INVALID.getIndex(), "失败"),
	ERROR(3, "系统繁忙，请稍后重试"),
	ILLEGAL_OPERATION(4, "非法操作"),
	LOGON_EXPIRES(5, "登录过期"),

	/**
	 * 11-100
	 */
	MISSING_PARAM(11, "参数缺失"),
	INVALID_PARAM(12, "参数非法"),
	INVALID_CHANNEL(13,"渠道非法"),
	USER_NOT_EXIST(14,"账户不存在"),
	CONFIG_INFO_NOT_EXIST(15,"配置信息不存在"),
	SAVE_USER_SUCCESS(16,"保存用户成功"),
	SAVE_USER_FAILED(17,"保存用户失败"),
    USER_ERROR(18, "账户信息异常"),
    ACCOUNT_OR_PASSWORD_ERROR(19, "账户或密码错误"),
	;
	
	
	private int index;
	private String message;
	private static final Map<Integer, StatusCode> enumMap = IndexedEnumUtil.toIndexMap(StatusCode.values());
	StatusCode(int index, String message) {
		this.index = index;
		this.message = message;
	}

	@Override
    public int getIndex() {
	    return index;
    }

	@Override
    public String getMessage() {
	    return message;
    }

	/**
	 * 根据指定的索引获取枚举的定义
	 *
	 * @param index
	 * @return
	 */
	public static StatusCode valueOf(final int index) {
		return enumMap.get(index);
	}

	public static void main(String[] args) {
		System.out.println(StatusCode.SUCCESS);
	}
}
